﻿@using viBook.Common
@using viBook.Helpers
@using viBook.Models
@using Language = viBook.Common.Language
@using Page = viBook.Models.Page
@helper RenderLanguages()
{
    @:[
    for (int i = 0; i < Constant.Languages.Count; i++)
    {
        Language language = Constant.Languages[i];
        if (i < Constant.Languages.Count - 1)
        {
            @:new Language('@language.DisplayName','@language.GoogleCodeLanguage'),
        }
        else
        {
            @:new Language('@language.DisplayName','@language.GoogleCodeLanguage')
        }
    }
    @:]
}
@helper InternetExplorer6Warning()
{ 
    @:<!--[if lt IE 7]> <div style='clear: both; height: 59px; padding: 0 0 0 15px; position: relative;'> <a href="http://windows.microsoft.com/en-US/internet-explorer/products/ie/home?ocid=ie6_countdown_bannercode"><img src="http://www.theie6countdown.com/images/banners/warning_bar_0000_us.jpg" border="0" height="42" width="820" alt="You are using an outdated browser. For a faster, safer browsing experience, upgrade for free today." /></a></div> <![endif]--> 
}
@helper ChapterCommentsToJavaScriptConverter(IList<ChapterComment> chapterComments)
{
    @:[
    for (int i = 0; i < chapterComments.Count; i++)
    {
        if (i < chapterComments.Count - 1)
        {
            @:new Comment(@chapterComments[i].Id,'@Helpers.ConvertToHtmlString(@chapterComments[i].User.DisplayName)','@chapterComments[i].User.AvatarUrl','@Helpers.ConvertToHtmlString(chapterComments[i].Content)','@chapterComments[i].CreatedDate.ConvertDateToString()','@chapterComments[i].Like',@chapterComments[i].IsLiked.BooleanToJavascript(),@chapterComments[i].IsReported.BooleanToJavascript(),@chapterComments[i].IsAuthorized.BooleanToJavascript()),
        }
        else
        {
            @:new Comment(@chapterComments[i].Id,'@Helpers.ConvertToHtmlString(@chapterComments[i].User.DisplayName)','@chapterComments[i].User.AvatarUrl','@Helpers.ConvertToHtmlString(chapterComments[i].Content)','@chapterComments[i].CreatedDate.ConvertDateToString()','@chapterComments[i].Like',@chapterComments[i].IsLiked.BooleanToJavascript(),@chapterComments[i].IsReported.BooleanToJavascript(),@chapterComments[i].IsAuthorized.BooleanToJavascript())
        }
    }
    @:]
}
@helper PagesToJavaScriptConverter(IList<Page> pages)
{
    @:[
    for (int i = 0; i < pages.Count; i++)
    {
        Page currentPage = pages[i];
        @: new Picture(@currentPage.Id, '@currentPage.ImageSource', [
        for (int j = 0; j < currentPage.Tags.ToList().Count; j++)
        {
            Tag currentTag = currentPage.Tags.ToList()[j];
            if (j < currentPage.Tags.ToList().Count - 1)
            {
                @:new Tag('@currentTag.Position', '@currentTag.TranslatedText'),
            }
            else
            {
                @:new Tag('@currentTag.Position', '@currentTag.TranslatedText')
            }
        }
        @:])
        if (i < pages.Count - 1)
        {
            @:,
        }
    }
    @:]
}
@helper ContentTagsToJavaScriptConverter(List<ContentTag> contentTags)
{
    @:[
    for (int i = 0; i < contentTags.Count; i++)
    {
        ContentTag contentTag = contentTags[i];
        if (i < contentTags.Count - 1)
        {
            @:new ContentTag(@contentTag.Id, '@Helpers.ConvertToHtmlString(@contentTag.ContentTagName)',@contentTag.NumberOfBook),
        }
        else
        {
            @:new ContentTag(@contentTag.Id, '@Helpers.ConvertToHtmlString(@contentTag.ContentTagName)',@contentTag.NumberOfBook)
        }
    }
    @:]
}
@helper TagsToJavaScriptConverter(List<Tag> tags)
{
    @:[
    for (int i = 0; i < tags.Count; i++)
    {
        Tag tag = tags[i];
        if (i < tags.Count - 1)
        {
            @:new Tag(@tag.Id, '@tag.Position','@tag.ConvertedText','@tag.TranslatedText'),
        }
        else
        {
            @:new Tag(@tag.Id, '@tag.Position','@tag.ConvertedText','@tag.TranslatedText')
        }
    }
    @:]
}
@helper PageToJavaScriptConverter(Page page)
{
    @:new Picture(@page.Id, '@page.ImageSource')
}
@helper BooksToJavaScriptConverter(List<Book> books)
{
    @:[
    for (int i = 0; i < books.Count; i++)
    {
        Book book = books[i];
        if (i < books.Count - 1)
        {
            if ((i + 1)%3 == 0)
            {
                @:new Book('@Helpers.ConvertDes(book.Description) ',@book.Id, '@Helpers.ConvertToHtmlString(@book.Title)','@book.CoverUrl',@book.NumberOfPage,@book.NumberOfChapters,@book.NumberOfLikes,@book.NumberOfViews,@book.NumberOfComments,'@book.UploaderAvartar','@Helpers.ConvertToHtmlString(@book.UploaderName)',@book.UploadedBy,'@(@book.UploadedDate.ConvertDateToString())','group third'),
            }
            else
            {
                @:new Book('@Helpers.ConvertDes(book.Description) ',@book.Id, '@Helpers.ConvertToHtmlString(@book.Title)','@book.CoverUrl',@book.NumberOfPage,@book.NumberOfChapters,@book.NumberOfLikes,@book.NumberOfViews,@book.NumberOfComments,'@book.UploaderAvartar','@Helpers.ConvertToHtmlString(@book.UploaderName)',@book.UploadedBy,'@(@book.UploadedDate.ConvertDateToString())','group'),
            }
        }
        else
        {
            if ((i + 1)%3 == 0)
            {
                @:new Book('@Helpers.ConvertDes(book.Description) ',@book.Id, '@Helpers.ConvertToHtmlString(@book.Title)','@book.CoverUrl',@book.NumberOfPage,@book.NumberOfChapters,@book.NumberOfLikes,@book.NumberOfViews,@book.NumberOfComments,'@book.UploaderAvartar','@Helpers.ConvertToHtmlString(@book.UploaderName)',@book.UploadedBy,'@(@book.UploadedDate.ConvertDateToString())','group third')
            }
            else
            {
                @:new Book('@Helpers.ConvertDes(book.Description) ',@book.Id, '@Helpers.ConvertToHtmlString(@book.Title)','@book.CoverUrl',@book.NumberOfPage,@book.NumberOfChapters,@book.NumberOfLikes,@book.NumberOfViews,@book.NumberOfComments,'@book.UploaderAvartar','@Helpers.ConvertToHtmlString(@book.UploaderName)',@book.UploadedBy,'@(@book.UploadedDate.ConvertDateToString())','group')
            }
        }
    }
    @:]
}
@helper ChapterToJavaScriptConverter(List<Chapter> chapters)
{
    @:[
    for (int i = 0; i < chapters.Count; i++)
    {
        Chapter chapter = chapters[i];
        if (i < chapters.Count - 1)
        {
            @:new Chapter(@chapter.Id, '@chapter.ChapterName', '@chapter.ChapterImage',@chapter.NumberOfPages,'@chapter.Content',@chapter.ChapterNumber),
        }
        else
        {
            @:new Chapter(@chapter.Id, '@chapter.ChapterName', '@chapter.ChapterImage',@chapter.NumberOfPages,'@chapter.Content',@chapter.ChapterNumber)
        }
    }
    @:]
}
@helper BookCommentsToJavaScriptConverter(IList<BookComment> bookComment)
{
    @:[
    for (int i = 0; i < bookComment.Count; i++)
    {
        if (i < bookComment.Count - 1)
        {
    @:new Comment(@bookComment[i].Id,'@Helpers.ConvertToHtmlString(@bookComment[i].User.DisplayName)','@bookComment[i].User.AvatarUrl','@Helpers.ConvertToHtmlString(@bookComment[i].Content)','@Helpers.ConvertDateToString(@bookComment[i].CreatedDate)',@bookComment[i].Like,@bookComment[i].IsLiked.BooleanToJavascript(),@bookComment[i].IsReported.BooleanToJavascript(),@bookComment[i].IsAuthorized.BooleanToJavascript()),
        }
        else
        {                                                                                                                                                                                                                                      
    @:new Comment(@bookComment[i].Id,'@Helpers.ConvertToHtmlString(@bookComment[i].User.DisplayName)','@bookComment[i].User.AvatarUrl','@Helpers.ConvertToHtmlString(@bookComment[i].Content)','@Helpers.ConvertDateToString(@bookComment[i].CreatedDate)',@bookComment[i].Like,@bookComment[i].IsLiked.BooleanToJavascript(),@bookComment[i].IsReported.BooleanToJavascript(),@bookComment[i].IsAuthorized.BooleanToJavascript())
        }
    }
    @:]
}
@helper CategoriesToJavaScriptConverter(IList<Category> categories)
{
    @:[
    for (int i = 0; i < categories.Count; i++)
    {
        if (i < categories.Count - 1)
        {
            @:new Category (@categories[i].Id,'@categories[i].CategoryName',
            @BooksToJavaScriptConverter(@categories[i].ListBook.ToList())
            @:),
        }
        else
        {
            @:new Category (@categories[i].Id,'@categories[i].CategoryName',
            @BooksToJavaScriptConverter(@categories[i].ListBook.ToList())
            @:)
        }
    }
    @:]
}
@helper ContentTagsToJavaScriptConverter(IList<ContentTag> contentTags)
{
    @:[
    for (int i = 0; i < contentTags.Count; i++)
    {
        if (i < contentTags.Count - 1)
        {
            @:new ContentTag (@contentTags[i].Id, '@Helpers.ConvertToHtmlString(@contentTags[i].ContentTagName)'),
        }
        else
        {
            @:new ContentTag (@contentTags[i].Id, '@Helpers.ConvertToHtmlString(@contentTags[i].ContentTagName)')
        }
    }
    @:]
}
@helper UserToJavaScriptConverter(IList<User> users)
{
    @:[
    for (int i = 0; i < users.Count; i++)
    {
        if (i < users.Count - 1)
        {
            @:new User (@users[i].Id, '@users[i].AvatarUrl','@Helpers.ConvertToHtmlString(@users[i].DisplayName)', @users[i].NumberOfUploadedBook),
        }
        else
        {
            @:new User (@users[i].Id, '@users[i].AvatarUrl','@Helpers.ConvertToHtmlString(@users[i].DisplayName)', @users[i].NumberOfUploadedBook)
        }
    }
    @:]
}
@helper ActivitiesToJavaScriptConverter(IList<Activity> activities)
{
    @:[
    for (int i = 0; i < activities.Count; i++)
    {
        if (i < activities.Count - 1)
        {
            @:new Activity (@activities[i].Id, @activities[i].UserId,'@activities[i].Description','@(@activities[i].CreatedDate.ConvertDateToString())','@activities[i].Type',@activities[i].ReferId),
        }
        else
        {
            @:new Activity (@activities[i].Id, @activities[i].UserId,'@activities[i].Description','@(@activities[i].CreatedDate.ConvertDateToString())','@activities[i].Type',@activities[i].ReferId)
        }
    }
    @:]
}
@helper PageCollectionToJavaScriptConverter(IList<Page> pages)
{
    @:[
    for (int i = 0; i < pages.Count; i++)
    {
        Page page = pages[i];
        if (i < pages.Count - 1)
        {
            @:new Page (@page.Id,'@page.Number', '@page.ImageSource'),
        }
        else
        {
            @:new Page (@page.Id,'@page.Number', '@page.ImageSource')
        }
    }
    @:]
}

@helper ListPageToJavaScriptConverter(IList<Page> pages)
    {
    @:[
    for (int i = 0; i < pages.Count; i++)
    {
        if (i < pages.Count - 1)
        {
    @:new Page (@pages[i].Id, '@pages[i].ImageSource',@pages[i].Number),
        }
        else
        {
    @:new Page (@pages[i].Id, '@pages[i].ImageSource',@pages[i].Number)
        }

    }
    @:]
}
